package algotithm.interview.shoppee.test4;

/**
 * @author zhouyanxiang
 * @Date 2021-03-2021/3/17-15:28
 */
import java.util.*;
class TreeNode {
    int val;
    Solution.TreeNode left;
    Solution.TreeNode right;
    public TreeNode(int val) {
        this.val = val;
    }
}
public class Solution {


    static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;
        public TreeNode(int val) {
            this.val = val;
        }
    }

    public List<List<Integer>> zigzagLevelOrder(TreeNode root) {
        List<List<Integer>> res = new ArrayList<>();
        Queue<TreeNode> q = new LinkedList<>();
        if (root == null) {
            return res;
        }
        q.offer(root);
        while (!q.isEmpty()) {
            int size = q.size();
            List<Integer> list = new LinkedList<>();
            while (size-- > 0) {
                TreeNode node = q.poll();
                list.add(node.val);
                if (node.left != null) {
                    q.offer(node.left);
                }
                if (node.right != null) {
                    q.offer(node.right);
                }
            }
            res.add(list);
        }
        return res;
    }

}

